@include('admin.header')
<div class="x-body">
  <form class="layui-form" action="" method="post">
    <input type="hidden" value="{{$user->user_id}}" name="user_id"/>
    <div class="layui-form-item">
      <label for="goods_name" class="layui-form-label">
        <span class="x-red">*</span>用户名称
      </label>
      <div class="layui-input-inline">
        <input type="text" id="goods_name" name="user_name" required lay-verify="required"
               autocomplete="off" class="layui-input" value="{{$user->user_name}}">
      </div>
    </div>
    <div class="layui-form-item">
      <label for="goods_info" class="layui-form-label">
        <span class="x-red">*</span>用户邮箱
      </label>
      <div class="layui-input-inline">
        <input type="text" id="goods_info" name="user_email" required lay-verify="required"
               autocomplete="off" class="layui-input" value="{{$user->user_email}}">
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label for="desc" class="layui-form-label">
        用户地址
      </label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容" id="desc" name="user_address" class="layui-textarea" style="resize: none;">{{$user->user_address}}</textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <label for="goods_desc" class="layui-form-label">
        <span class="x-red">*</span>联系电话
      </label>
      <div class="layui-input-inline">
        <input type="text" id="goods_desc" name="user_tel" required lay-verify="required"
               autocomplete="off" class="layui-input" value="{{$user->user_tel}}">
      </div>
    </div>
    <div class="layui-form-item">
      <label for="addtime" class="layui-form-label">
        <span class="x-red">*</span>添加时间
      </label>
      <div class="layui-input-inline">
        <input class="layui-input" placeholder="开始日" name="user_addtime" id="addtime" value="{{$user->user_addtime}}">
      </div>
    </div>
    <div class="layui-form-item">
      <label for="L_repass" class="layui-form-label">
      </label>
      <button  class="layui-btn" lay-filter="add" lay-submit="">
        保存
      </button>
    </div>
  </form>
</div>
<div class="alert">
  提示信息
</div>
<style>
  .alert{
    position: fixed;
    width: 280px;
    height: 50px;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    z-index: 9999;
    color: #fff;
    text-align: center;
    line-height: 50px;
    font-size: 16px;
    display: none;
  }
</style>
<script>
  //重置分页的样式
  function resetpage(){
    //把span标签改成a标签
    var spans = parent.$('.page-item span');
    for (let i = 0; i < spans.length; i++) {
      spans[i].outerHTML="<a href=''>"+spans[i].innerHTML+"</a>";
    }
    var arr = parent.$(".page-item a");
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].innerHTML=="‹") {
        arr[i].className = "prev";
      }else if(arr[i].innerHTML=="›"){
        arr[i].className = "next";
      }
    }
    //将当前页设置为active
    parent.$(".active a").attr("class","num active");
    //把li 上面的active 去除
    parent.$("li.active").removeClass("active");
    //给页码a标签换类名
    parent.$(".page-item .page-link").attr("class","num");
  }
  //更新父级窗口的数据
  function getGoodData(page){
    $.ajax({
      type:"get",
      url:"{{url('/admin/toget_user_list')}}",
      data:"page="+page,
      dataType:"html",
      success:function(res){
        parent.$(".list").html(res);
        resetpage();

      }
    })
  }
  //请求接口获取所有数据的条数
  function getCount(){
    $.ajax({
      type:"get",
      url:"{{url('/admin/toget_user_count')}}",
      data:"",
      dataType:"text",
      success:function(res){
        parent.$(".count").html("共有会员："+res+" 人");
      }
    })
  }

  layui.use('laydate', function(){
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
      elem: '#addtime' //指定元素
    });

  });

  layui.use(['form','layer'], function(){
    $ = layui.jquery;
    var form = layui.form
            ,layer = layui.layer

    //监听提交
    form.on('submit(add)', function(data){

      //data.field.good_dec = layedit.getContent(index);




      console.log(data.field);
      dataobj = data.field;


      $.ajax({
        url:"/admin/todo_user_edit",
        type:"post",
        data: dataobj,

        dataType:"json",
        success: function(res) {
          console.log(res);
          if(res.code==1){
            getGoodData(1);
            getCount();
            layer.alert(res.msg,function () {
              // 获得frame索引
              var index = parent.layer.getFrameIndex(window.name);
              //关闭当前frame
              parent.layer.close(index);
            });
          }else{
            layer.alert(res.msg);
          }
        },
        error:function(data) {
          $(".alert").html("服务器错误！").css({"background-color":"#41b314bb","border-color":"#3ca512bb"}).stop().fadeIn(500);
          setTimeout(function () {
            $(".alert").fadeOut(500);
          },2000)
        }
      });
      //发异步，把数据提交给php

      return false;
    });
  });
</script>
</body>
</html>